package com.cloudlead.plugin.security.action;

import com.cloudlead.common.worker.annotation.*;
import com.cloudlead.common.worker.security.PasswordHelper;
import com.cloudlead.plugin.security.BusinessModules;
import com.cloudlead.common.lang.persistence.*;

import java.util.List;

import com.cloudlead.common.worker.action.impl.AbstractCrudActionFactory;
import com.cloudlead.plugin.security.vo.ScUser;
import com.cloudlead.plugin.security.action.validator.ScUserValidatorGroup.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.cloudlead.common.lang.annotation.Label;
import com.cloudlead.plugin.security.service.ScUserService;

import javax.validation.constraints.NotNull;

/**
 * ScUserActionFactory is a Codegen action factory type
 */
@Controller("scUserActionFactory")
@Label("用户管理")
public class ScUserActionFactory extends AbstractCrudActionFactory<ScUserService, ScUser> {

    @Autowired
    public ScUserActionFactory(ScUserService ScUserService) {
        super(BusinessModules.ScUser, ScUserService);
    }

    @Action
    @Order(1)
    @Label("查询用户的权限")
    public List<String> findPrivileges(@NotNull @Label("用户名") String username, @Label("用户组") String group) {
        return service.findPrivileges(username, group);
    }

    @Action
    @Order(2)
    @Label("查询用户的角色")
    public List<String> findRoles(@NotNull @Label("用户名") String username, @Label("用户组") String group) {
        return service.findRoles(username, group);
    }

    @Action
    @Order(3)
    @Label("查询用户所属组")
    public List<String> findGroups(@NotNull @Label("用户名") String username) {
        return service.findGroups(username);
    }

    @Action
    @Order(10)
    @ValidatorGroup(Create.class)
    @Label("创建")
    @Override
    public ScUser create(@NotNull ScUser vo) {
        vo.setPassword(PasswordHelper.encryption(vo.getPassword(), vo.getSalt()));
        return super.create(vo);
    }

    @Action
    @Order(11)
    @ValidatorGroup(Update.class)
    @Label("更新")
    @Override
    public ScUser update(@NotNull ScUser vo) {
        vo.setPassword(PasswordHelper.encryption(vo.getPassword(), vo.getSalt()));
        return super.update(vo);
    }

    @Action
    @Order(12)
    @Label("批量更新")
    @Override
    public void updateAll(@NotNull ScUser vo, @NotNull Filter filter) {
        super.updateAll(vo, filter);
    }

    @Action
    @Order(13)
    @Label("根据实例批量更新")
    @Override
    public void updateAllByExample(@NotNull ScUser vo, @NotNull @Label("实例") ScUser example) {
        super.updateAllByExample(vo, example);
    }

    @Action
    @Order(14)
    @Label("查看")
    @Override
    public ScUser view(@NotNull @Label("编号") String id) {
        return super.view(id);
    }

    @Action
    @Order(15)
    @Label("单值查询")
    @Override
    public ScUser findOne(@NotNull Filter filter) {
        return super.findOne(filter);
    }

    @Action
    @Order(16)
    @Label("根据实例单值查询")
    @Override
    public ScUser findOneByExample(@NotNull @Label("实例") ScUser example) {
        return super.findOneByExample(example);
    }

    @Action
    @Order(17)
    @Label("统计")
    @Override
    public long count(Filter filter) {
        return super.count(filter);
    }

    @Action
    @Order(18)
    @Label("根据实例统计")
    @Override
    public long countByExample(@NotNull @Label("实例") ScUser example) {
        return super.countByExample(example);
    }

    @Action
    @Order(19)
    @Label("列表查询")
    @Override
    public List<ScUser> list(Filter filter, Sort sort) {
        return super.list(filter, sort);
    }

    @Action
    @Order(20)
    @Label("根据实例列表查询")
    @Override
    public List<ScUser> listByExample(@NotNull @Label("实例") ScUser example) {
        return super.listByExample(example);
    }

    @Action
    @Order(21)
    @Label("分页查询")
    @Override
    public Page<ScUser> findAll(@NotNull PageRequest pageable) {
        return super.findAll(pageable);
    }

    @Action
    @Order(22)
    @Label("删除")
    @Override
    public ScUser delete(@NotNull @Label("编号") String id) {
        return super.delete(id);
    }

    @Action
    @Order(23)
    @Label("批量删除")
    @Override
    public void deleteAll(Filter filter) {
        super.deleteAll(filter);
    }

    @Action
    @Order(24)
    @Label("根据实例批量删除")
    @Override
    public void deleteAllByExample(@Label("实例") ScUser example) {
        super.deleteAllByExample(example);
    }

}

